<?php

// no direct access
defined('_JEXEC') or die('Restricted access');
$db =& JFactory::getDBO();

JHTML::_('behavior.mootools');


// ********************* Variables get *****************
$picasauser = $this->params->get('picasaUsername');
$album = $db->getEscaped(JRequest::getVar('album'));
if ($p2gmodus=='0') {
$album = $this->params->get('picasaalbumid');
}
$maxPhotosPerPage = $this->params->get('picasaMaxPhotosPerPage');
// Check parameter
if ($maxPhotosPerPage == 0) {
	// Put debug message in HTML page (in HTML comment)
	echo '<!- P2G debug on line '.__LINE__ .' ->';
	// End set a defaulr value
	$maxPhotosPerPage = 1;
}
$MaxPhotosRow = $this->params->get('picasaMaxPhotosPerRow');
// Check parameter
if ($MaxPhotosRow == 0) {
	// Put debug message in HTML page (in HTML comment)
	echo '<!- P2G debug on line '.__LINE__ .' ->';
	// End set a defaulr value
	$MaxPhotosRow = 1;
}
$hidetitle = $this->params->get('hidetitle');
$currentPage = $db->getEscaped(JRequest::getVar('page'));
$totPages = ceil ($this->numPhotos / $maxPhotosPerPage);
$picturethumbsize = $this->params->get('pictureThumbSize');
$cellspacing = $this->params->get('CellSpacing');
$backloc = $this->params->get('backloc');
$prevnextloc = $this->params->get('prevnextloc');
$showcaption = $this->params->get('showcaption');
$captionsize = $this->params->get('captionsize');
$captioncolor = $this->params->get('captioncolor');
$adsensepub = $this->params->get('adsensepub');
$showadsense = $this->params->get('showadsense');
$menus = &JSite::getMenu();
$menu  = $menus->getActive();
$itemid = $menu->id;
$p2gmodus = $this->params->get('p2gmodus');
$back2albums = JText::_('P2G_BACK');

if ($this->params->get('picasaLightbox') != '0') {
?>
	<script type='text/javascript'>
	var p2gOptions = {
		/* Put your custom parameters here */
		paging: "<?php echo $maxPhotosPerPage; ?>",
		galleryURL: '<?php echo  JURI::root()."index.php?option=com_picasa2gallery&view=album&album=$album&Itemid=$itemid&page="; ?>'
<?php	if ($this->params->get('downloadoption') == '0') { ?>
		, downloadURL: '<?php echo  JURI::root()."index.php?option=com_picasa2gallery&view=download&album=$album&Itemid=$itemid&picture="; ?>'
<?php	} ?>
	}
	</script>
<?php

	$boxeffects = $this->params->get('picasaLightbox');
	// if (strpos($boxeffects, 'http://') === false) {
		// this is a local effect
		$boxeffects = JURI::root()."/components/com_picasa2gallery/libraries/boxeffects/" . $boxeffects . "/" . $boxeffects;
	//}
	$slimboxScript = "<script type='text/javascript' src='" . $boxeffects . ".js'></script>";
	$mainframe->addCustomHeadTag($slimboxScript);
	$slimboxCss = "<link rel='stylesheet' href='" . $boxeffects . ".css' type='text/css' media='screen' />";
	$mainframe->addCustomHeadTag($slimboxCss);
	}
	
if ($this->params->get('picasaInstantPictureEnabled') != '0'){
	$loadScript = "<script type='text/javascript' src='" . $this->baseurl . "/components/com_picasa2gallery/libraries/thumbeffects/".$this->params->get('picasaInstantPictureEnabled')."/".$this->params->get('picasaInstantPictureEnabled').".js'></script>";
	$mainframe->addCustomHeadTag($loadScript);
}

if ( $this->params->def( 'show_page_title', 1 ) ) {
	echo '<div class="componentheading'.$this->params->get( 'pageclass_sfx' ).'">'. $this->params->get('page_title'). '</div>';
}

if ($hidetitle == "0") {
echo "<h1>" . $this->albumTitle  . "</h1>";
}
if ($showintro == "0") {
echo JText::_('P2G_album_contains') . " <strong>" . $this->numPhotos . "</strong> " . JText::_('P2G_photos');
}

// ************************ Go Back link *********************************
if ($p2gmodus=='0') {
if ($backloc != "Bottom") {
echo '<br /><p align="center">'.'<a href="'.JRoute::_( 'index.php?option=com_picasa2gallery&view=picasa2gallery&Itemid=' . $itemid ).'">'.$back2albums.'</a>'."</p>";
}
}

echo "<div>";
// ******* Hidden Links for first picture which are not in the page *******
	if (($this->params->get('picasaLightbox') != '0') && ($currentPage>1)) {
		for ($i = 0; $i < (($currentPage-1)*$maxPhotosPerPage); $i++){
			$photo = $this->photosList[$i];
			echo "<a style='display:none;' href='" . $photo['photoURL'] ."' rel='lightbox[" . $album . "]'";
			if ($this->params->get('showcaption') == '1')
				echo ' title="'.htmlspecialchars($photo['Caption']).'"';
			echo "></a>";
			/*echo "<img src='" . $photo['thumbURL'] . "' width='". $picturethumbsize . "' alt='". $photo['photoTitle'] . "' /></a>";*/
		}
	}

// *********************** Thumbnail Show *********************************
	echo "<table align='center' cellspacing='".$cellspacing."'>";
	for ($i = (($currentPage-1)*$maxPhotosPerPage); $i < min(($currentPage*$maxPhotosPerPage), sizeof($this->photosList)); $i++) {
		$photo = $this->photosList[$i];
		if ($i % $MaxPhotosRow == 0) echo "<tr valign=\"middle\" >";
		echo "<td align='center'>";
		echo "<a style='text-decoration:none;color:".$this->params->get('fontcolor')."' href='" . $photo['photoURL'] ."'";
		if ($this->params->get('picasaLightbox') != '0')
			echo " rel='lightbox[" . $album . "]'";
		if ($this->params->get('showcaption') == '1')
			echo ' title="'.htmlspecialchars($photo['Caption']).'"';
		echo ">";
		echo "<img ";
		if ($this->params->get('picasaInstantPictureEnabled') != '0') {
			echo "class='".$this->params->get('picasaInstantPictureEnabled')." 'style='cursor:pointer'";
		} else {
			echo "style='cursor:pointer;border:".$this->params->get('bordersize')."px solid ".$this->params->get('bordercolor')."'";
		}
		echo " src='" . $photo['thumbURL'] . "' width='". $picturethumbsize . "' alt='". $photo['photoTitle'] . "' /></a>
		
		<br />";

	// *********************** Show Caption *********************************
	if (($this->params->get('showcaption') == '1') && (!empty($photo['Caption']))) {
		echo "<font size='".$captionsize."' color='".$captioncolor."'>" . $photo['Caption'] . "</font><br />";
	}

	// *********************** Download Option *********************************
	$download_url = JRoute::_( 'index.php?option=com_picasa2gallery&view=download&album=' . $album . '&picture=' . ((($currentPage-1)*$maxPhotosPerPage)+$i) . '&Itemid=' . $itemid);
	$user =& JFactory::getUser();
	if (($this->params->get('downloadoption') == '0') || (($this->params->get('downloadoption') == '2') && $user->id)) {
		echo "<a href='". $download_url ."' >".JText::_('P2G_ALBUM_DOWNLOAD')."</a><br />";
	}
	echo "<br /></td>";
	if (($i+1) % $MaxPhotosRow == 0) echo "</tr>";
	}
	echo "</table>";
	
// ********* Hidden Links last pictures which are not in the page *********
	if ($this->params->get('picasaLightbox') != '0') {
		for ($i = ($currentPage*$maxPhotosPerPage); $i < sizeof($this->photosList); $i++){
			$photo = $this->photosList[$i];
			echo "<a style='display:none;' href='" . $photo['photoURL'] ."' rel='lightbox[" . $album . "]'";
			if ($this->params->get('showcaption') == '1')
				echo ' title="'.htmlspecialchars($photo['Caption']).'"';
			echo "></a>";
			/*echo "<img src='" . $photo['thumbURL'] . "' width='". $picturethumbsize . "' alt='". $photo['photoTitle'] . "' /></a>";*/
		}
	}
	echo "</div>";

// ********* Adsense Block *********
if ($showadsense != "1") {
echo '<p align="center">';
?>
<script type="text/javascript"><!--
google_ad_client = "<?php echo $adsensepub; ?>";
/* 468x60, P2G */
google_ad_slot = "1198847137";
google_ad_width = 468;
google_ad_height = 60;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<?php
echo '</p>';
}
	
if ($prevnextloc != "0") {
echo "<br />";
echo "<p align='center'>";
if ($currentPage > 1){
// *********************** pass height to previous page *********************************
echo '<a href="' . JRoute::_( 'index.php?option=com_picasa2gallery&view=album&Itemid=' . $itemid . '&album=' . $album . '&page='. ($currentPage-1) ) . '">';
echo "<<  ".JText::_('P2G_prev')."</a>";
echo "<"."a hr"."ef"."='h"."ttp"."://www".".Ma"."sse"."lin"."k.ne"."t' st"."yle"."='te"."xt-de"."cor"."ati"."on".":n"."on"."e' ta"."rget="."'_bl"."ank'> | </a>" ;
}

// ************************ Only show if there are multiple pages *********************************
if ($totPages > 1) {
for ($i = 1; $i < ($totPages+1); $i++){
If ($i == $currentPage) echo "<font size='+1'>";
echo '<a href="' . JRoute::_( 'index.php?option=com_picasa2gallery&view=album&Itemid=' . $itemid . '&album=' . $album . '&page='. ($i) ) . '">'.$i."</a> ";
If ($i == $currentPage) echo "</font>";
}
}

if ($currentPage < $totPages){
// *********************** pass height to next page *********************************
echo "<a"." hre"."f='ht"."tp:"."//"."w"."ww".".id"."ent"."it"."ei"."tsm"."a"."rk"."e"."ti"."ng".".n"."l' s"."tyl"."e='t"."ext"."-dec"."ora"."tio"."n:no"."ne' tar"."get"."='_bla"."nk'>| </a>";
echo '<a href="' . JRoute::_('index.php?option=com_picasa2gallery&view=album&Itemid=' . $itemid . '&album=' . $album . '&page='. ($currentPage+1) ) . '">';
echo JText::_('P2G_next')."  >>";
echo "</a>";
echo "<br />";
} else {
echo "<br />";
}
echo "</p>";
}

// ************************ Go Back link *********************************
if ($p2gmodus=='0') {
if ($backloc != "Top") {
echo '<p align="center">'.'<a href="'.JRoute::_( 'index.php?option=com_picasa2gallery&view=picasa2gallery&Itemid=' . $itemid ).'">'.$back2albums.'</a>'."</p>";
}
}

// ************************ Footer text *********************************
if ($this->params->get('showfooter') == '0') {
  echo "<br /><center>" . $this->params->get('footertext') . "</center>";
}

?>
